// 1. 高阶函数
// 将函数作为参数的函数 或者 将函数作为返回值的函数
// lodash中广泛使用  debounce  throttle
// 1. before after 的实现

function coreFunction(a, b, c) {
  console.log(a, b, c);
}

Function.prototype.before = function (cb) {
  let callbacks = [];
  if (this.callbacks) {
    callbacks = this.callbacks;
  }
  callbacks.push(cb);
  this.callbacks = callbacks;
  const baseFunc = this;
  return function (...args) {
    baseFunc.callbacks.forEach((callback) => {
      callback(...args);
    });
    baseFunc.call(this, ...args);
  };
};
const encCoreFunc = coreFunction.before(function (...args) {
  console.log("before1", ...args);
});
coreFunction.before(function (...args) {
  console.log("before2", ...args);
});
coreFunction.before(function (...args) {
  console.log("before3", ...args);
});

encCoreFunc(1, 2, 3);
